package day14.tarena.homeword;

import day13.tarena.com.Equals;

public class Product 
		implements Comparable<Product>{
		private String id;
		private String name;
		private String addr;
		private double price;
		
		
		public Product() {
			super();
		}
		public Product(String id, String name, String addr, double price) {
			super();
			this.setId(id);  //调用的方法，代码复用。
			this.setName(name);
			this.setAddr(addr);
			this.setPrice(price);
		}
		public String getAddr() {
			return addr;
		}
		public void setAddr(String Addr) {
			this.addr = Addr;
		}
		public String getId() {
			return id;
		}
		public void setId(String id) {
			this.id = id;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public double getPrice() {
			return price;
		}
		public void setPrice(double price) {
			if(price > 0){
			this.price = price;
			}else{
				System.out.println("价格不正确");
			}
		}
		
		public int compareTo(Product p){
			 	if(p == null) return 0;
			 	return this.name.compareTo(p.name);
		}
		
		
		
		@Override
		public boolean equals(Object obj){
			if(obj == null )return false;
			else if(this.getClass() == obj.getClass()){
					Product p = (Product)obj;
					return p.id.equals(this.id);
			}
			return false;
		}
		
		@Override
		public int hashCode(){
			int type = this.getClass().hashCode();
			return type*31 + id.hashCode();
		}
		
		@Override
		public String toString(){
		
			return id + ":" + name + ":"+addr+":"+price; 
		}
		
}